import { PaginationResponse } from "@datorama/akita";

import { MessageItem, PendingMessage } from "@/models/Message";
import { TwMsgRevokeReq } from "@/models/request/msgReq";
import { rxRequest } from "@/utils/rxHelpers";
import CONFIG from "@/config";

export default {
  getUserSigSvc(userId: string) {
    return rxRequest<string>({
      url: CONFIG.BASE_URL + "/v1/msg/QCloud/avcAuth",
      withJwt: true,
      data: { userId },
      method: "POST"
    })
  },

  getPendingMsgsSvc(groupId: string, pageNum: number, pageSize: number) {
    return rxRequest<PaginationResponse<PendingMessage>>({
      url: CONFIG.BASE_URL + `/v1/msg/pendingMsgList/${groupId}`,
      withJwt: true,
      data: { pageNum, pageSize },
      method: "POST"
    })
  },

  passPendingMsgsSvc(groupId: string, ids: string[]) {
    return rxRequest({
      url: CONFIG.BASE_URL + `/v1/msg/passMsg/${groupId}`,
      data: { ids },
      withJwt: true,
      method: "POST"
    })
  },

  revokeTwMsgSvc(data: TwMsgRevokeReq) {
    return rxRequest({
      url: CONFIG.BASE_URL + '/v1/msg/twMsgList/revokeMsg',
      data,
      withJwt: true,
      method: "POST"
    })
  },

  //图文直播分页拉取消息
  getTuwenMsgSvc(groupId: string, pageNum: number, pageSize: number) {
    return rxRequest<PaginationResponse<MessageItem>>({
      url: CONFIG.BASE_URL + `/v1/msg/twMsgList/${groupId}`,
      withJwt: true,
      data: { pageNum, pageSize },
      method: "POST"
    })
  },

  sendGroupNotifyMsgSvc(groupId: string, cmd: string, data?: string) {
    return rxRequest({
      url: CONFIG.BASE_URL + "/v1/msg/sendGroupNotifyMsg",
      data: { groupId, cmd, data },
      withJwt: true,
      method: "POST"
    })
  },

  sendC2cMsgSvc(toAccount: string, cmd: string, data?: string) {
    return rxRequest({
      url: CONFIG.BASE_URL + "/v1/msg/sendC2cMsg",
      data: { toAccount, cmd, data },
      withJwt: true,
      method: "POST"
    })
  },

  updateLinkMicSvc(roomId: string, userId: string, status: number) {
    return rxRequest({
      url: CONFIG.BASE_URL + `/v1/live/room/${roomId}/updateLinkMic`,
      data: { linkerId: userId, status },
      withJwt: true,
      method: "PUT"
    })
  },
}